﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;

using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.ZP;
using Rison.BusinessFacade.Helper;
using Rison.DataAccess.Common;
using Rison.DataAccess.Data.ZP;

namespace Rison.BusinessFacade.Facade.ZP
{
    public sealed class YxsbFacade : FacadeBase
    {
        protected override DataAccessBase dbObject
        {
            get
            {
                if (dbHelper == null)
                    dbHelper = new  YxsbDb();

                return dbHelper;
            }
        }
       
         protected override string keyFieldName
        {
            get
            {
                return "ID";
            }
        }

         protected override List<SqlField> GetSqlFieldCollection(object value, bool getIdentityField)
         {
             List<SqlField> fields = new List<SqlField>();

             if (getIdentityField)
             {
                 fields.Add(new SqlField("ID", (value as yxsbb).ID, true, true));
             }
             else
             {
                 fields.Add(new SqlField("ID", (value as yxsbb).ID));
             }

             fields.Add(new SqlField("Year", (value as yxsbb).Year));
             fields.Add(new SqlField("DepartID", (value as yxsbb).DepartID));
             fields.Add(new SqlField("Title", (value as yxsbb).Title));
             fields.Add(new SqlField("Content", (value as yxsbb).Content));
             fields.Add(new SqlField("Anlx", (value as yxsbb).Anlx));
             fields.Add(new SqlField("Zy", (value as yxsbb).Zy));

             fields.Add(new SqlField("Creator", (value as yxsbb).Creator));
             fields.Add(new SqlField("CreateTime", (value as yxsbb).Year));
             fields.Add(new SqlField("LastModifed", (value as yxsbb).LastModifed));
             fields.Add(new SqlField("LastModifedTime", (value as yxsbb).LastModifedTime));

             return fields;
         }

         protected override object SetPropertiesValue(DataRow row)
         {
             yxsbb obj = new yxsbb();
             obj.ID = row["id"].ToString();
             obj.Year = StringHelper.GetValue(row, "Year");
             obj.DepartID = StringHelper.GetValue(row, "DepartID");
             obj.Title = StringHelper.GetValue(row, "Title");
             obj.Content = StringHelper.GetValue(row, "Content");
             obj.Anlx = StringHelper.GetValue(row, "Anlx");
             obj.Zy = StringHelper.GetValue(row, "Zy");
             obj.CreateTime = StringHelper.GetValue(row, "CreateTime");
             obj.Creator = StringHelper.GetValue(row, "Creator");
             obj.LastModifedTime = StringHelper.GetValue(row, "LastModifedTime");
             obj.LastModifed = StringHelper.GetValue(row, "LastModifed");

             return obj;
         }

         public DataRow GetYxsbRow(string id)
         {
             if (id == "")
                 return null;

             YxsbDb h = new YxsbDb();
             return h.GetInformationToRow(id);
         }
        
        public DataSet GetYxsbList(string departid, string year)
        {
            if (departid == "")
                return null;

            YxsbDb h = new YxsbDb();
            return h.GetInformation(departid, year);
        }

        //是否填报
        public bool isExistSelfExam(string departid, string year)
        {
            DataSet ds = GetYxsbList(departid, year);
            if (ds != null && ds.Tables[0].Rows.Count> 0)
            {
                return true;
            }

            return false;
        }
    }
}
